package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.StudentInformation;
import com.ruoyi.system.service.IStudentInformationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生情况Controller
 * 
 * @author ruoyi
 * @date 2024-09-20
 */
@RestController
@RequestMapping("/studentInfomation/information")
public class StudentInformationController extends BaseController
{
    @Autowired
    private IStudentInformationService studentInformationService;

    /**
     * 查询学生情况列表
     */
    @PreAuthorize("@ss.hasPermi('studentInfomation:information:list')")
    @GetMapping("/list")
    public TableDataInfo list(StudentInformation studentInformation)
    {
        startPage();
        List<StudentInformation> list = studentInformationService.selectStudentInformationList(studentInformation);
        return getDataTable(list);
    }

    /**
     * 导出学生情况列表
     */
    @PreAuthorize("@ss.hasPermi('studentInfomation:information:export')")
    @Log(title = "学生情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentInformation studentInformation)
    {
        List<StudentInformation> list = studentInformationService.selectStudentInformationList(studentInformation);
        ExcelUtil<StudentInformation> util = new ExcelUtil<StudentInformation>(StudentInformation.class);
        util.exportExcel(response, list, "学生情况数据");
    }

    /**
     * 获取学生情况详细信息
     */
    @PreAuthorize("@ss.hasPermi('studentInfomation:information:query')")
    @GetMapping(value = "/{familySituation}")
    public AjaxResult getInfo(@PathVariable("familySituation") String familySituation)
    {
        return success(studentInformationService.selectStudentInformationByFamilySituation(familySituation));
    }

    /**
     * 新增学生情况
     */
    @PreAuthorize("@ss.hasPermi('studentInfomation:information:add')")
    @Log(title = "学生情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StudentInformation studentInformation)
    {
        return toAjax(studentInformationService.insertStudentInformation(studentInformation));
    }

    /**
     * 修改学生情况
     */
    @PreAuthorize("@ss.hasPermi('studentInfomation:information:edit')")
    @Log(title = "学生情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StudentInformation studentInformation)
    {
        return toAjax(studentInformationService.updateStudentInformation(studentInformation));
    }

    /**
     * 删除学生情况
     */
    @PreAuthorize("@ss.hasPermi('studentInfomation:information:remove')")
    @Log(title = "学生情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{familySituations}")
    public AjaxResult remove(@PathVariable String[] familySituations)
    {
        return toAjax(studentInformationService.deleteStudentInformationByFamilySituations(familySituations));
    }
}
